home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / Developer University / DUProjects / Windoid / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-04-09  |  4.4 KB  |  171 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 1 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //================================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef DEFINES_K
  10. #include "Defines.k"
  11. #endif
  12.  
  13. #ifndef BINDING_K
  14. #include "Binding.k"
  15. #endif
  16.  
  17. #ifndef FRAME_H
  18. #include "Frame.h"
  19. #endif
  20.  
  21. // ----- Framework Layer -----
  22. #ifndef FWPRESEN_H
  23. #include "FWPresen.h"        // FW_CPresentation
  24. #endif
  25.  
  26. #ifndef FWUTIL_H
  27. #include "FWUtil.h"            // FW_Beep()
  28. #endif
  29.  
  30. #ifndef FWABOUT_H
  31. #include "FWAbout.h"        //::FW_About()
  32. #endif
  33.  
  34. #ifndef FWFLOWIN_H
  35. #include "FWFloWin.h"        // FW_CFloatingWindow
  36. #endif
  37.  
  38. // ----- OS Layer -----
  39. #ifndef   FWRESFIL_H
  40. #include "FWResFil.h"        // FW_CResourceFile
  41. #endif
  42.  
  43. #ifndef FWMENU_H
  44. #include "FWMenu.h"            // FW_CMenuBar, FW_CPullDownMenu
  45. #endif
  46.  
  47. #ifndef FWCFMRES_H
  48. #include "FWCFMRes.h"        // FW_CSharedLibraryResourceFile
  49. #endif
  50.  
  51. #ifndef FWEVENT_H
  52. #include "FWEvent.h"        // FW_CMenuEvent
  53. #endif
  54.  
  55. #ifndef FWPICTUR_H
  56. #include "FWPictur.h"        // FW_CPicture
  57. #endif
  58.  
  59. //==============================================================================
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment Windoid
  62. #endif
  63.  
  64. FW_DEFINE_AUTO(CWindoidPart)
  65. //==============================================================================
  66. CWindoidPart::CWindoidPart(ODPart* odPart)
  67.   :    FW_CPart(odPart, FW_gInstance, kPartInfoID),
  68.     fMainPresentation(NULL),
  69.     fPalettePresentation(NULL),
  70.     fPaletteWindow(NULL)
  71. {
  72.     FW_END_CONSTRUCTOR
  73. }
  74.  
  75. //--------------------------------------------------------------------------------
  76. CWindoidPart::~CWindoidPart()
  77. {
  78.     FW_START_DESTRUCTOR
  79. }
  80.  
  81. //--------------------------------------------------------------------------------
  82. void 
  83. CWindoidPart::Initialize(Environment* ev)    // Override
  84. {
  85. FW_DO_NOT_DEAD_STRIP(FW_CToggleItem);
  86.  
  87.     FW_CPart::Initialize(ev);
  88.     const FW_Boolean kDefault = TRUE;
  89.     const ODType kMainPresentation = "Apple:Presentation:Main";
  90.     const ODType kPalettePresentation = "Apple:Presentation:Palette";
  91.     fMainPresentation = this->RegisterPresentation(ev, kMainPresentation, kDefault);
  92.     fPalettePresentation = this->RegisterPresentation(ev, kPalettePresentation, !kDefault);
  93.     FW_CSharedLibraryResourceFile resFile(ev);
  94.     GetMenuBar(ev)->InitializeFromResource(ev, kMenuBarID);
  95. }
  96.  
  97. //--------------------------------------------------------------------------------
  98. FW_Boolean 
  99. CWindoidPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  100.                                      FW_Boolean hasMenuFocus,
  101.                                      FW_Boolean isRoot)    // Override
  102. {
  103.     if (hasMenuFocus) {    
  104.         menuBar->EnableAndToggleCommand(ev, cShowHideCommand, true, 
  105.                     fPaletteWindow == NULL || !fPaletteWindow->IsShown(ev));
  106.     }
  107.     return FALSE;
  108. }
  109.  
  110. //--------------------------------------------------------------------------------
  111. FW_Boolean 
  112. CWindoidPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  113. {
  114.     FW_Boolean menuHandled = true;    
  115.     switch (theMenuEvent.GetCommandID(ev))
  116.     {
  117.         case kODCommandAbout:
  118.             ::FW_About(ev, this, kAbout);
  119.             break;
  120.  
  121.         case cShowHideCommand:
  122.             fPaletteWindow->ShowHide(ev, ! fPaletteWindow->IsShown(ev));
  123.             break;
  124.  
  125.         default:
  126.             menuHandled = false;
  127.     }
  128.     return menuHandled;
  129. }
  130.  
  131. //--------------------------------------------------------------------------------
  132. FW_CFrame* 
  133. CWindoidPart::NewFrame(Environment* ev, ODFrame* odFrame,
  134.                         FW_CPresentation* presentation, FW_Boolean fromStorage)    // Override
  135. {
  136.     FW_UNUSED(fromStorage);
  137.     if (presentation == fPalettePresentation) {
  138.         return FW_NEW( CPaletteFrame, (ev, odFrame, presentation, this) );
  139.     }
  140.     return FW_NEW( CMainFrame, (ev, odFrame, presentation, this) );
  141. }
  142.  
  143. //------------------------------------------------------------------------------
  144. FW_CContent* 
  145. CWindoidPart::NewPartContent(Environment* ev)
  146. {
  147.     return NULL;
  148. }
  149.  
  150. //--------------------------------------------------------------------------------
  151. void 
  152. CWindoidPart::MyMakePalette(Environment* ev, FW_Boolean showWindow)
  153. {
  154.     if (fPaletteWindow == NULL)
  155.     {
  156.         FW_CSharedLibraryResourceFile     resFile(ev);    // palette picture here
  157.         FW_CPicture picture(resFile, kPalettePictID);
  158.         FW_CRect bounds;
  159.         picture.GetPictBounds(bounds);
  160.         FW_CPoint windowSize = bounds.Size();
  161.         FW_CPoint windowPosition(FW_IntToFixed(100), FW_IntToFixed(100));
  162.         const FW_Boolean kWantCloseBox = true;
  163.         const FW_CString32 kWindowTitle("");
  164.         fPaletteWindow =  new FW_CFloatingWindow(ev, this, 
  165.                                 fPalettePresentation, kWindowTitle, 
  166.                                 windowSize, windowPosition, kWantCloseBox);
  167.         if (showWindow)
  168.             fPaletteWindow->Show(ev);
  169.     }
  170. }
  171.